﻿Imports System.ComponentModel
Imports DevExpress.Skins
Imports DevExpress.LookAndFeel
Imports DevExpress.UserSkins
Imports DevExpress.XtraBars
Imports DevExpress.XtraBars.Ribbon
Imports DevExpress.XtraBars.Helpers


Public Class Form1
    Sub New()
        InitSkins()
        InitializeComponent()
        Me.InitSkinGallery()

    End Sub
    Sub InitSkins()
        DevExpress.Skins.SkinManager.EnableFormSkins()
        DevExpress.UserSkins.BonusSkins.Register()
        UserLookAndFeel.Default.SetSkinStyle("DevExpress Style")

    End Sub
    Private Sub InitSkinGallery()
        SkinHelper.InitSkinGallery(rgbiSkins, True)
    End Sub

    Private Sub iExit_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles iExit.ItemClick
        Close()
    End Sub

    Private Sub NavQLNha_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavQLNha.LinkClicked
        pctFrom.Controls.Clear()
        Dim u As New UCNha()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub

    Private Sub NavQLHoaDon_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavQLHoaDon.LinkClicked
        pctFrom.Controls.Clear()
        Dim u As New UCHoaDon()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub

    Private Sub NavQLKhachHang_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavQLKhachHang.LinkClicked
        pctFrom.Controls.Clear()
        Dim u As New UCKhachHang()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub

    Private Sub NavQLDonViCungCap_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavQLDonViCungCap.LinkClicked
        pctFrom.Controls.Clear()
        Dim u As New UCDVCungCap()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub

    Private Sub NavQLBaoCao_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavQLBaoCao.LinkClicked

        pctFrom.Controls.Clear()
        Dim u As New UCBaoCao()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub

    Private Sub NavQLNhanVien_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavQLNhanVien.LinkClicked
        pctFrom.Controls.Clear()
        Dim u As New UCNhanVien()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub

    Private Sub NavLoaiNha_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavLoaiNha.LinkClicked
        pctFrom.Controls.Clear()
        Dim u As New UCLoaiNha()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub
    Private Sub NavThemTaiKhoan_LinkClicked(ByVal sender As System.Object, ByVal e As DevExpress.XtraNavBar.NavBarLinkEventArgs) Handles NavThemTaiKhoan.LinkClicked
        pctFrom.Controls.Clear()
        Dim u As New UCCapTaiKhoan()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub
    Private Sub barbtnDoiMK_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnDoiMK.ItemClick
        pctFrom.Controls.Clear()
        Dim u As New UCDoiMatKhau()
        pctFrom.Controls.Add(u)
        u.Dock = DockStyle.Fill
    End Sub

    Public Sub ShowTool()
        If USER.IsLogin <> True Then
            Return
        End If
        If USER.MaCV = 1 Then
            NavGAdmin.Visible = True
            NavGQL.Visible = False
            NavGBaocao.Visible = False
            RibbonPGDulieu.Visible = True
        ElseIf USER.MaCV = 2 Then
            NavGAdmin.Visible = False
            NavGQL.Visible = True
            NavGBaocao.Visible = True
        End If
    End Sub
    Sub DisableTool()
        NavGQL.Visible = False
        NavGBaocao.Visible = False
        NavGAdmin.Visible = False
        RibbonPGDulieu.Visible =False
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DisableTool()
        Dim l As New frmLogin
        l.ShowDialog()
        ShowTool()
    End Sub

    Private Sub barbtnDangxuat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnDangxuat.ItemClick
        USER.IsLogin = False
        DisableTool()
        pctFrom.Controls.Clear
    End Sub

    Private Sub BarbtnDangNhap_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarbtnDangNhap.ItemClick
        USER.IsLogin = False
        DisableTool()
        pctFrom.Controls.Clear()
        Dim l As New frmLogin
        l.ShowDialog()
        ShowTool()
    End Sub

    
    Private Sub BarbtnBackup_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarbtnBackup.ItemClick
        Dim sf As New SaveFileDialog
        sf.Filter = "Database (*.bak)|*.bak"
        sf.ShowDialog()
        Dim File_name As String = sf.FileName
        Dim sql As String = String.Format("Backup database QLPHONGTRO to disk = '{0}'", File_name)
        DataProvider.ExecuteNonQuery(sql)
        If sf.ShowDialog() <> DialogResult.OK Then
            MessageBox.Show("Backup dữ liệu không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop)
            Return
        End If
        MessageBox.Show("File đã được lưu vào ổ đĩa ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub BarbtnRestore_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarbtnRestore.ItemClick
        ''Restore database QLPHONGTRO from disk = '{0}'

        Try
            Dim ofd As New OpenFileDialog
            ofd.Filter = "Database (*.bak)|*.bak"
            ofd.ShowDialog()
            Dim File_name As String = ofd.FileName
            Dim sql As String = String.Format("Backup database QLPHONGTRO to disk = '{0}'", File_name)
            DataProvider.ExecuteNonQuery(sql)
            If ofd.ShowDialog() <> DialogResult.OK Then
                MessageBox.Show("Backup dữ liệu không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop)
                Return
            End If
            MessageBox.Show("Khôi phục dữ liệu thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End Try

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If MessageBox.Show("Bạn cố muốn kết thúc phần mềm Quản lý phòng trọ không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
            e.Cancel = True
        End If


    End Sub
End Class
